/**
 * BootPassiveThread.java
 * ************************** 
 * @date Apr 26, 2011
 * @author Michele Tamburini
 * 
 * **************************
 */
package gossipServices.bootstraping.theBootstrapingService;

import gossipServices.basic.nodeDescriptors.NodeDescriptor;
import gossipServices.basic.view.PartialView;
import gossipServices.gossipMessages.BootstrapingMessage;
import gossipServices.gossipThread.PassiveGossipThreadInterface;
import gossipServices.network.NetworkServicesAPI;
import gossipServices.pss.PeerSamplingServiceAPI;

/**
 * Description: 
 *
 */
public class BootPassiveThread extends BootstrapingMiddleware 
		implements PassiveGossipThreadInterface {

	/**
	 * @param name
	 * @param cycleLenghtMsec
	 * @param view
	 * @param pss
	 * @param nsa
	 */
	public BootPassiveThread(String name, long cycleLenghtMsec,
			PartialView view, PeerSamplingServiceAPI pss, NetworkServicesAPI nsa) {
		super(name, cycleLenghtMsec, view, pss, nsa);
		gossipProtocol = this;
	}

	@Override
	public void gossipThreadInstructions() throws InterruptedException {
		passiveThreadInstructions();
	}
	
	@Override
	public void passiveThreadInstructions() throws InterruptedException {
		BootstrapingMessage msgq = (BootstrapingMessage) nsa.receive();
		NodeDescriptor q = msgq.getSender();
		BootstrapingMessage myAnswer = createMessage(q);
		nsa.send(myAnswer,q);
		updateLeafSet(msgq);
		updatePrefixTable(msgq);		
	}


}
